package demo.dao;

import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import demo.dbconnection.DBConnection;

public class CardTimesDAO
{
	private static int id;
	private static int count;
	private static String exDate;
	private static int valid;
	private static DBConnection DBConn;

	public CardTimesDAO()
	{
		DBConn = new DBConnection();
		DBConn.open();
	}

	public static void setId(int inId)
	{
		id = inId;
	}

	public static void setCount(int inCount)
	{
		count = inCount;
	}

	public static boolean save()
	{
		Date date = new Date();
		date.setYear(date.getYear() + 3);// 次卡3年过期
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式

		exDate = df.format(date);
		String sql = "insert into card_times(id,count,EX_DATE,valid) values("
				+ id + "," + count + ",'" + exDate + "',1);";
		DBConn.update(sql);
		return true;
	}
}
